home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gpp-1_42.lha / g++-1.42.0 / cplus-ptree.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  5KB  |  235 lines

  1. /* Prints out tree in human readable form - GNU C++ compiler
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. #include "config.h"
  23. #include "tree.h"
  24. #include "cplus-tree.h"
  25. #include <stdio.h>
  26.  
  27.  
  28. extern char *tree_code_err_name[];
  29. extern char *tree_code_err_asg_name[];
  30. extern char *mode_name[];
  31.  
  32. extern char spaces[];
  33.  
  34. #define MIN(x,y) ((x < y) ? x : y)
  35.  
  36. static FILE *outfile;
  37.  
  38. /* This code is copied from print-tree.c.  */
  39. static
  40. void
  41. wruid (node)
  42.      tree node;
  43. {
  44.  
  45.   if (node == NULL)
  46.     fputs ("<>", outfile);
  47.   else {
  48.     fprintf (outfile, "%1d", TREE_UID (node));
  49.   }
  50. }
  51.  
  52. static 
  53. void
  54. part (title, node)
  55.      char title[];
  56.      tree node;
  57. {
  58.   fprintf (outfile, " %s = ", title);
  59.   wruid (node);
  60.   putc (';', outfile);
  61. }
  62.  
  63. /* Similar to `part' but prefix with @ if value is not constant
  64.    and print the constant value if it is constant.  */
  65. static
  66. void
  67. cpart (title, ct, punct)
  68.      char *title;
  69.      tree ct;
  70.      char punct;
  71. {
  72.   fprintf (outfile, " %s = ", title);
  73.   if (ct == NULL)
  74.     fputs ("<>", outfile);
  75.   else
  76.     {
  77.       if (!TREE_LITERAL (ct))
  78.     {
  79.       putc ('@', outfile);
  80.       wruid (ct);
  81.     }
  82.       else
  83.     fprintf (outfile, "%ld", TREE_INT_CST_LOW (ct));
  84.     }
  85.   putc (punct, outfile);
  86. }
  87.  
  88. void
  89. print_lang_decl (node)
  90.      tree node;
  91. {
  92. }
  93.  
  94. void walk_lang_decl (node)
  95.      tree node;
  96. {
  97. }
  98.  
  99. void
  100. print_lang_type (node)
  101.      register tree node;
  102. {
  103.   int first;
  104.   if (! (TREE_CODE (node) == RECORD_TYPE
  105.      || TREE_CODE (node) == UNION_TYPE))
  106.     return;
  107.   first = 1;
  108.   fputs (" [", outfile);
  109.   if (TYPE_NEEDS_CONSTRUCTOR (node))
  110.     {
  111.       if (!first) putc (' ', outfile);
  112.       fputs ("needs-constructor", outfile);
  113.       first = 0;
  114.     }
  115.   if (TYPE_NEEDS_DESTRUCTOR (node))
  116.     {
  117.       if (!first) putc (' ', outfile);
  118.       fputs ("needs-destructor", outfile);
  119.       first = 0;
  120.     }
  121.   if (TYPE_HAS_CONVERSION (node))
  122.     {
  123.       if (!first) putc (' ', outfile);
  124.       fputs ("has-type-conversion", outfile);
  125.       first = 0;
  126.     }
  127.   if (TYPE_HAS_INT_CONVERSION (node))
  128.     {
  129.       if (!first) putc (' ', outfile);
  130.       fputs ("has-int-conversion", outfile);
  131.       first = 0;
  132.     }
  133.   if (TYPE_HAS_REAL_CONVERSION (node))
  134.     {
  135.       if (!first) putc (' ', outfile);
  136.       fputs ("has-float-conversion", outfile);
  137.       first = 0;
  138.     }
  139.   if (TYPE_HAS_INIT_REF (node))
  140.     {
  141.       if (!first) putc (' ', outfile);
  142.       fputs ("X(X&)", outfile);
  143.       first = 0;
  144.     }
  145.   if (TREE_GETS_NEW (node))
  146.     {
  147.       if (!first) putc (' ', outfile);
  148.       fputs ("gets-new", outfile);
  149.       first = 0;
  150.     }
  151.   if (TREE_GETS_DELETE (node))
  152.     {
  153.       if (!first) putc (' ', outfile);
  154.       fputs ("gets-delete", outfile);
  155.       first = 0;
  156.     }
  157.   if (TYPE_HAS_ASSIGNMENT (node))
  158.     {
  159.       if (!first) putc (' ', outfile);
  160.       fputs ("has=", outfile);
  161.       first = 0;
  162.     }
  163.   if (TYPE_GETS_ASSIGNMENT (node))
  164.     {
  165.       if (!first) putc (' ', outfile);
  166.       fputs ("gets=", outfile);
  167.       first = 0;
  168.     }
  169.   if (TYPE_HAS_ASSIGN_REF (node))
  170.     {
  171.       if (!first) putc (' ', outfile);
  172.       fputs ("this=(X&)", outfile);
  173.       first = 0;
  174.     }
  175.   if (TYPE_GETS_ASSIGN_REF (node))
  176.     {
  177.       if (!first) putc (' ', outfile);
  178.       fputs ("gets=(X&)", outfile);
  179.       first = 0;
  180.     }
  181.   if (TYPE_HAS_WRAPPER (node))
  182.     {
  183.       if (!first) putc (' ', outfile);
  184.       fputs ("wrapper", outfile);
  185.       first = 0;
  186.     }
  187.   if (TYPE_OVERLOADS_METHOD_CALL_EXPR (node))
  188.     {
  189.       if (!first) putc (' ', outfile);
  190.       fputs ("op->()", outfile);
  191.       first = 0;
  192.     }
  193.   if (TYPE_GETS_INIT_AGGR (node))
  194.     {
  195.       if (!first) putc (' ', outfile);
  196.       fputs ("gets X(X, ...)", outfile);
  197.       first = 0;
  198.     }
  199.   if (TYPE_OVERLOADS_CALL_EXPR (node))
  200.     {
  201.       if (!first) putc (' ', outfile);
  202.       fputs ("op()", outfile);
  203.       first = 0;
  204.     }
  205.   if (TYPE_OVERLOADS_ARRAY_REF (node))
  206.     {
  207.       if (!first) putc (' ', outfile);
  208.       fputs ("op[]", outfile);
  209.       first = 0;
  210.     }
  211.   if (TYPE_USES_MULTIPLE_INHERITANCE (node))
  212.     {
  213.       if (!first) putc (' ', outfile);
  214.       fputs ("uses-multiple-inheritance", outfile);
  215.       first = 0;
  216.     }
  217.  
  218.   fputs ("] ", outfile);
  219. }
  220.  
  221. void
  222. walk_lang_type (node)
  223.      tree node;
  224. {
  225.   if (! (TREE_CODE (node) == RECORD_TYPE))
  226.     return;
  227.  
  228.   part ("member functions", CLASSTYPE_METHOD_VEC (node));
  229.   part ("baselinks", CLASSTYPE_BASELINK_VEC (node));
  230.   cpart ("offset", CLASSTYPE_OFFSET (node), ';');
  231.   fprintf (outfile, "n_parents = %d; n_ancestors = %d;",
  232.        CLASSTYPE_N_BASECLASSES (node),
  233.        CLASSTYPE_N_SUPERCLASSES (node));
  234. }
  235.